import Vue from "vue"
import App from "./App.vue"
import Cookies from "js-cookie"

import store from "./store"
import router from "./router/"

import "@/styles/index.scss" // 全局css

// 引入vxe-table
import "./vxetable"

import "./icons"
import "./permission" // 权限控制

// 导入element-ui
import ElementUI from "element-ui"
import "element-ui/lib/theme-chalk/index.css"

Vue.use(ElementUI, {
  size: Cookies.get("size") || "mini"
})

// 下拉树
//引入下拉树文件
import Treeselect from "@riophae/vue-treeselect"
import "@riophae/vue-treeselect/dist/vue-treeselect.css"
Vue.component("Treeselect", Treeselect)
// 组件通讯
export const eventBus = new Vue()

// 导入时间格式化组件库moment
import moment from "moment"
// 定义时间格式化全局过滤器
Vue.filter("dateFormat", function(dateStr, pattern = "YYYY-MM-DD HH:mm:ss") {
  return moment(dateStr).format(pattern)
})
// 注册插件treetable的需求
import TreeTable from "vue-table-with-tree-grid"

// 导入按钮权限控制
import btnControl from "@/directive/btnControl.js"
Vue.use(btnControl)

// 导入富文本编辑器
import VueQuillEditor from "vue-quill-editor"
// require styles 导入富文本编辑器对应样式
import "quill/dist/quill.core.css"
import "quill/dist/quill.snow.css"
import "quill/dist/quill.bubble.css"

if (process.env.NODE_ENV === "staging") {
  const { mockXHR } = require("../mock")
  mockXHR()
}

// 将全局的echarts挂载到Vue的原型链对象上   使用this.$echarts
Vue.prototype.$echarts = window.echarts

Vue.config.productionTip = false

// 手动注册组件
Vue.component("tree-table", TreeTable)
// 将富文本编辑器，注册为全局可用的组件
Vue.use(VueQuillEditor)

// 时间全局过滤器   padStart 如果某个字符串不够指定长度，会在头部或尾部补全。padStart()用于头部补全，padEnd()用于尾部补全
Vue.filter("dateFormat", function(originVal) {
  const dt = new Date(originVal)
  const y = dt.getFullYear()
  const m = (dt.getMonth() + 1 + "").padStart(2, "0")
  const d = (dt.getDate() + "").padStart(2, "0")

  const hh = (dt.getHours() + "").padStart(2, "0")
  const mm = (dt.getMinutes() + "").padStart(2, "0")
  const ss = (dt.getSeconds() + "").padStart(2, "0")
  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})

new Vue({
  el: "#app",
  router,
  store,
  render: h => h(App)
})
